﻿using System;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;

namespace content.A06
{
    public partial class A0602:Page
    {
        public A0602()
        {
            InitializeComponent();
            TextBoxFilePath.Text=@"A:\A0601\aaa.txt";
            TextBoxText.Text="202000800593李俊彦";
            ButtonBrowser.Click+=(s,e)=>
            {
                OpenFileDialog file=new OpenFileDialog();
                if(file.ShowDialog()==true)
                {
                    TextBoxFilePath.Text=file.FileName;
                    TextBoxText.Text="";
                    string[] str=File.ReadAllLines(TextBoxFilePath.Text);
                    TextBoxText.Text=string.Join("\r\n",str);
                }
            };
            ButtonRead.Click+=(s,e)=>
            {
                try
                {
                    string[] str=File.ReadAllLines(TextBoxFilePath.Text);
                    TextBoxText.Text=string.Join("\r\n",str);
                }
                catch(Exception err)
                {
                    MessageBox.Show(err.Message);
                    TextBoxText.Text="";
                }
            };
            ButtonSave.Click+=(s,e)=>
            {
                try
                {
                    File.WriteAllLines(TextBoxFilePath.Text,TextBoxText.Text.Split(new string[] {"\r\n"},StringSplitOptions.None));
                    MessageBox.Show("保存成功!");
                }
                catch(Exception err)
                {
                    MessageBox.Show(err.Message,"保存失败!");
                }
            };
        }
    }
}